package com.example.http;

import org.apache.http.client.utils.URIBuilder;
import org.junit.Test;
import sun.nio.cs.ext.GBK;

import java.net.URISyntaxException;

/**
 * @Author：wlz
 * @Package：com.example.http
 * @Project：redis
 * @name：GetTest
 * @Date：2023/6/3 19:07
 * @Filename：GetTest
 */
public class GetTest {

    @Test
    public void test() throws URISyntaxException {
        String url = "http://www.google.com/search?hl=en&q=httpclient&btnG=Google+Search&aq=f&oq=";
        URIBuilder uriBuilder = new URIBuilder(url);
        System.out.println(uriBuilder.getScheme());
        System.out.println(uriBuilder.getUserInfo());
        System.out.println(uriBuilder.getHost());
        System.out.println(uriBuilder.getPort());
        System.out.println(uriBuilder.getPath());
        System.out.println(uriBuilder.getQueryParams());
        System.out.println(uriBuilder.getFragment());
        System.out.println(uriBuilder.getCharset());

//        输出如下所示：
//        scheme：http
//        userinfo：null
//        host：www.google.com
//        port：-1  端口默认是80，当显示指定端口时，此处便能取到值
//        path：/search
//        queryParams：[hl=en, q=httpclient, btnG=Google Search, aq=f, oq=]
//        fragment：null
//        charset：null

    }

    @Test
    public void test1() throws URISyntaxException {

//        某些属性含义未知手动设置一次
        String url1 = "http://info.sporttery.cn/football/info/fb_match_hhad.php?m=102909";
        URIBuilder uriBuilder1 = new URIBuilder(url1);
        uriBuilder1.setFragment("111");
        uriBuilder1.setUserInfo("222", "333");
        uriBuilder1.setCharset(new GBK());
        System.out.println(uriBuilder1.build());
        System.out.println(uriBuilder1.getScheme());
        System.out.println(uriBuilder1.getUserInfo());
        System.out.println(uriBuilder1.getHost());
        System.out.println(uriBuilder1.getPath());
        System.out.println(uriBuilder1.getQueryParams());
        System.out.println(uriBuilder1.getFragment());
        System.out.println(uriBuilder1.getCharset());

//        输出如下：
//        http://222:333@info.sporttery.cn/football/info/fb_match_hhad.php?m=102909#111
//        scheme：http
//        userInfo：222:333   没见过这东西-。-
//                host：info.sporttery.cn
//        path：/football/info/fb_match_hhad.php
//        queryParams：[m=102909]
//        fragment：111   路由
//        charset：GBK
    }
}
